package com.cci.kangdao.controller;

import com.cci.kangdao.aop.annotation.NoDuplicateSubmission;
import com.cci.kangdao.service.ServiceTechniciansListService;
import com.cci.kangdao.utilTool.ParameterTool;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 服务技师资质列表类controller
 *
 */
@Controller
public class ServiceTechniciansListController {
	
	private Logger log = Logger.getLogger(this.getClass().getName());

	@Autowired
	private ServiceTechniciansListService serviceTechniciansListService;
	
	/**
	 * 根据服务站id和服务技师用户id获取服务技师资质列表
	 * @param request
	 * @return
	 */
	@RequestMapping("/getEngineerQualifyListByServiceStationIdUserId.aspx")
	public ModelAndView getEngineerQualifyListByServiceStationIdUserId(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return serviceTechniciansListService.getEngineerQualifyListByServiceStationIdUserId(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}

	@RequestMapping("/getEngineerQualifyVerifyByServiceStationId.aspx")
	public ModelAndView getEngineerQualifyVerifyByServiceStationId(HttpServletRequest request,
																   HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return serviceTechniciansListService.getEngineerQualifyVerifyByServiceStationId(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);

			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}


	/**
	 * 判断服务技师是否有资质
	 * @param
	 * @return
	 */
	@RequestMapping("/isHaveEngineerQualify.aspx")
	public ModelAndView isHaveEngineerQualify(HttpServletRequest request, HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return serviceTechniciansListService.isHaveEngineerQualify(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);

			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}


	
	/**
	 * 服务主管提交服务技师
	 * @param map
	 * @return
	 */
    @NoDuplicateSubmission
    @RequestMapping("/submitServiceTechnician.aspx")
    public ModelAndView submitServiceTechnician(HttpServletRequest request,
                                                HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return serviceTechniciansListService.submitServiceTechnician(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
}
